package com.zhoug.zmui3demo.ui;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.widget.TextView;

import com.zhoug.zmui3.ZMUIEmptyView;
import com.zhoug.zmui3.ZMUITopView;
import com.zhoug.zmui3.ints.OnClickListener;
import com.zhoug.zmui3demo.R;

import java.security.SecureRandom;
import java.util.Random;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

/**
 * 测试ZMUIEmptyView
 * @Author: zhoug
 * @Date: 2023/9/27
 * @Description:
 */
public class TestZMUIEmptyViewActivity extends AppCompatActivity {
    private Handler mMainHandler=new Handler(Looper.getMainLooper());
    private ZMUITopView mTopView;
    private ZMUIEmptyView mEmptyView;
    private TextView mTvContent;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.text_zmui_emptyview_activity);
        findViews();
        mTvContent.setVisibility(View.GONE);

        //模拟数据请求
        mMainHandler.postDelayed(requestData,2000);

    }

    private Runnable requestData=new Runnable() {
        @Override
        public void run() {
            Random random=new SecureRandom();
            int status = random.nextInt(3);
            if(status==0){
                //数据请求成功
                mEmptyView.hide();
                mTvContent.setVisibility(View.VISIBLE);
            }else if(status==1){
                //数据为空
                mTvContent.setVisibility(View.GONE);
                mEmptyView.show(R.drawable.zmui_image_emptyview_empty,"暂无内容",null,"重新加载",null);

            }else {
                //数据请求失败
                mTvContent.setVisibility(View.GONE);
                mEmptyView.show(R.drawable.zmui_image_emptyview_error,"数据请求失败",null,"重新加载",null);
            }
        }
    };

    private OnClickListener onClickListener=new OnClickListener() {
        @Override
        public void onClick(View view) {
            mMainHandler.postDelayed(requestData,2000);
        }
    };

    private void findViews() {
        mTopView = findViewById(R.id.topView);
        mEmptyView = findViewById(R.id.emptyView);
        mTvContent = findViewById(R.id.tv_content);
    }
}
